﻿using System;

namespace SoCGadget.Robotics.XBee
{
    /// <summary>
    /// Event args for log messages.
    /// </summary>
    public class LogEventArgs : EventArgs
    {
        public LogEventArgs(string senderName, string msg)
        {
            _message = string.Format("{0}: {1}", senderName, msg);
        }

        public string Message
        {
            get { return _message; }
        }

        private readonly string _message;
    }

    /// <summary>
    /// Event args for data sample reveived events from an XBee device.
    /// </summary>
    public class DataSampleReceivedArgs : EventArgs
    {
        public ulong SourceSerialNumber { get; set; }
        public ushort SourceAddress { get; set; }
        public DigitalData DigitalChannelMask { get; set; }
        public DigitalData DigitalIO { get; set; }
        public DigitalData AnalogChannelMask { get; set; }
        public ushort[] AnalogIO { get; set; }

        public DataSampleReceivedArgs(
            ulong sourceSerialNumber,
            ushort sourceAddress,
            ushort digitalChannelMask,
            ushort digitalSample,
            byte analogChannelMask,
            ushort[] analogSamples)
        {
            SourceSerialNumber = sourceSerialNumber;
            SourceAddress = sourceAddress;
            // only first 13 bits are valid masks
            DigitalChannelMask = new DigitalData(13, digitalChannelMask);
            DigitalIO = new DigitalData(13, digitalSample);
            // only first 4 bits are valid masks
            AnalogChannelMask = new DigitalData(8, analogChannelMask);
            AnalogIO = analogSamples;
        }
    }
}
